package com.kang.delay;

import com.kang.utils.RabbitMQUtils;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author: zhangkangkang
 * @Description: 延迟队列
 * @date 2021/8/3 15:02
 */
public class Test2 {
    public static void main(String[] args) throws IOException, InterruptedException {
        Connection connection = RabbitMQUtils.getConnection();
        Channel channel = connection.createChannel();
        channel.queueDelete("mq2");
        Map map = new HashMap();
        //消息的过期时间,删除消息
        map.put("x-message-ttl", 5000);
        channel.queueDeclare("mq2", false, false, false, map);
        channel.basicPublish("", "mq2", null, "hello".getBytes());
        Thread.sleep(2000);
        System.out.println("开始发送第二条消息");
        channel.basicPublish("", "mq2", null, "hello".getBytes());
        RabbitMQUtils.closeConnectionAndChanel(channel, connection);
    }
}
